//消息头部
import React, {Component} from 'react'
import {Text, TouchableOpacity,} from 'react-native';

import {fetchRequest} from '../../../util/fetch';
import {newsStyle as styles} from '../../../../styles';


export default class Newsin_list extends Component {

    constructor(props) {
        super(props);
        this.state = {
            isR: true,
            isok: false,
        }
    }


    isRead(msgId) {
        fetchRequest('xzMsg/isReadByIdMob.go', 'POST', {msgId: msgId}).then(ret => {
            if (ret.msg === 'ok') {
                this.props.toRead(msgId);
            }
        });
    }

    componentDidUpdate() {
        if (this.props.msg.msgIsread === 1 && !this.state.isR) {
            this.setState({isR: true});
        } else if (this.props.msg.msgIsread === 0 && this.state.isR) {
            this.setState({isR: false});
        }
    }

    render() {
        return (
            <TouchableOpacity
                style={styles.news_allin}
                onPress={() => {
                    this.isRead(this.props.msg.msgId);
                    this.props.navigation.navigate('Newsinall', {
                        msg: this.props.msg
                    });
                }}

                activeOpacity={1}>

                {this.state.isR ? <Text style={styles.news_evn2}/>
                    : <Text style={styles.news_evn}/>}

                <Text style={styles.news_con}>{this.props.msg.msgContent}</Text>
            </TouchableOpacity>

        )
    }
}